<?php
$skin = Zend_Registry::get('skin');
$bookedSeats = $this->bookedSeats;
$bookedSeatCount = count ($bookedSeats);
$totalSeatCount = $this->totalSeatCount;
$seatNumberAndStatusMap = $this->seatNumberAndStatusMap;
$nonFixedSeatTicketIDs = $this->nonFixedSeatTicketIDs; 

// calculate free seat count
$freeSeatCount = $totalSeatCount - $bookedSeatCount;
?>

<?php
// draw this page only if freeSeatCount > 0 (prevent logical error in database)
if($freeSeatCount > 0) { ?>
<div id="errorReport"><p>Làm ơn refresh lại trang này nếu bạn vừa dùng nút <span style="font-weight: bold">Back</span></p></div>
<div id="seatPanel">

<div class="TBB_content">
<h2 class="">Danh sách chỗ ngồi</h2>
<p class="">Làm ơn chọn số chỗ ngồi cần đặt. Nếu cần chọn vị trí chỗ ngồi thì chọn vào "phần tùy chọn" 
và chọn ghế ở bảng bên phải.</p>
</div>
<hr></hr>
<form action="/customers/enter-info" method="post" id="ticketForm">

<?php
echo $this->formHidden('fromTicketList', true);

// tripID hidden form element
echo $this->formHidden('trip', $this->tripID, array('style' => 'display: none'));
?>


<div id="container" class="container span-20 last">

<!-- ============================= Select seat count you want ================================ -->
<?php 
	// prepare for seatCountYouWant select element
	$selectOptions = array();
	$seatCountYouWant = min($freeSeatCount, 5);
	for($i = 1; $i <= $seatCountYouWant; ++$i) {
		$selectOptions[$i] = $i;
	}
?>
<table id="selectSeat" class="span-6"  style="background-color: #ccf;">
	<tr>
		<td class="span-3">Số chỗ ngồi</td>
		<td class="span-2 last">
		<?php
			// this is seat count you want 
			echo $this->formSelect('seatCountYouWant', 1, array('class' => 'span-2'), $selectOptions); 
		?>
		</td>
	</tr>
		
	<tr>
		<td></td>
		<td class="last">		
		<input id="orderTickets" type="image" value="Chấp nhận" src="/skins/<?php echo $skin; ?>/images/accept.png"/>		
		</td>			
	</tr>	

	<tr>
		<td id="optional" colspan="2" class="last">
			(Phần tùy chọn)
		</td>
	</tr>
	
	<tr>
		<td>Chọn chỗ ngồi</td>
		<td class="last">
			<input value="no" id="doYouSelectSeat" name="doYouSelectSeat" type="checkbox"/>
		</td>
	</tr>
</table>


<!-- ============================= Instruction ================================ -->
<?php
	$colorNames = array('Ghế đã đặt', 'Ghế trống', 'Ghế đặt tạm', 'Ghế bạn đặt');
	$colorValues = array('gray', 'green', 'aqua', 'red');
?>

<table id="instruction" class="span-5" style="background-color: #ccf;">
<?php for($i = 0; $i < count($colorNames); ++$i): ?>
<tr>
	<td class="span-2"><div class="span-2"><?php echo $colorNames[$i];?></div></td>
	<td class="span-2 last"><div class="span-2 last" style="background-color: <?php echo $colorValues[$i]; ?>">&nbsp;</div></td>
</tr>
<?php endfor;?>
</table>

<!-- ============================= Blocks board ================================ -->
<?php 

?>

<table id="blocks" class="span-8 last">
<tbody>
<?php for($i = 1; $i <= $totalSeatCount; ) {?>
	<tr>
	<?php for($k = 1; $k <= 4 && $i <= $totalSeatCount; ) {?>
		<?php if($k == 3) {?>
		<td class="blocksMidWay span-1">&nbsp;</td>	
		<?php }?>			

		<td id="<?php echo 'seatNumber' . $i; ?>" class="span-2 
					<?php 
					$printCheckBox = true;
					//$printFreeSeat = true;
						// check if it is booked seat
						if(array_key_exists($i, $seatNumberAndStatusMap)) {
							// if it is fixed seat, set it to blocksFixedSeat
							if($seatNumberAndStatusMap[$i] != false){
								echo 'blocksFixedSeat';
								$printCheckBox = false;
							} else {
								echo 'blocksTempSeat';
							}
							
						}
						// else it is unbooked seat
						else {								
							echo 'blocksNormalSeat';
							
						}
		?>">		
		<?php if($printCheckBox == true) { ?>
			<input type="text" id="<?php echo 'seats' . $i; ?>" name="seats[<?php echo $i; ?>]" value="no"/>
		<?php } ?>				
		<?php echo $i++; ++$k; ?>
		</td>
		<?php } ?>
	</tr>
<?php } ?>
</tbody>
</table>

</div>

<div id="tempSeatDivs">
<?php
foreach($nonFixedSeatTicketIDs as $index => $id) {
	echo $this->formHidden('tempSeats[]', $id, array('id' => 'tempSeats' . $id));	
}
?>
</div>
</form>

</div>
<?php } else { ?>
<div class="large">
<div>Chuyến này đã hết chỗ.</div>
<a href="/">Trở về trang chủ</a>
</div>
<hr></hr>
<?php }?>
